package org.kgc.alanhealth.service.impl;

import org.kgc.alanhealth.entity.HospitalDrugs;
import org.kgc.alanhealth.entity.HospitalSymptom;
import org.kgc.alanhealth.entity.HospitalSymptomatic;
import org.kgc.alanhealth.mapper.HospitalDrugsMapper;
import org.kgc.alanhealth.mapper.HospitalSymptomMapper;
import org.kgc.alanhealth.mapper.HospitalSymptomaticMapper;
import org.kgc.alanhealth.service.DrugStoreService;
import org.kgc.alanhealth.vo.HospitalDrugsDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class DrugStoreServiceImpl implements DrugStoreService {
    @Autowired
    HospitalSymptomaticMapper hospitalSymptomaticMapper;
    @Autowired
    HospitalDrugsMapper hospitalDrugsMapper;
    @Autowired
    HospitalSymptomMapper hospitalSymptomMapper;
    @Override
    public List<HospitalSymptomatic> getAllSymptomatic() {
        return hospitalSymptomaticMapper.getAllSymptomatic();
    }
    @Override
    public List<HospitalDrugsDetail> getAllDrugs(Integer currentPageNo, Integer pageSize){return hospitalDrugsMapper.getAllByDrugs((currentPageNo-1)*pageSize,pageSize);}

    @Override
    public List<HospitalSymptom> getAllSymptomById(int id) {
        return hospitalSymptomMapper.getAllSymptomById(id);
    }

    @Override
    public List<HospitalDrugsDetail> getDrugById(long id) {
        return hospitalDrugsMapper.selectByPrimaryKey(id);
    }

    @Override
    public int getAllByDrugsCount() {
        return hospitalDrugsMapper.getAllByDrugsCount();
    }

    @Override
    public List<HospitalDrugsDetail> getDrugByCondition(String keyword) {
        List<HospitalDrugsDetail> drugsList = new ArrayList<>();

        List<HospitalDrugsDetail> drugsByDrugName = hospitalDrugsMapper.selectByDrugName(keyword);
        drugsList.addAll(drugsByDrugName);

        List<HospitalDrugsDetail> drugsByDrugName1 = hospitalDrugsMapper.selectBydrugDescription(keyword);
        drugsList.addAll(drugsByDrugName1);


        return drugsList;
    }

}
